<?php
class cls_control_permission extends cls_control_base
{
	function show()
	{
		$permission_serve = parent::get_serve();
		$permission_serve->check_permission('PERMISSION_ALLOCATION');
		
		$permission_tree = $permission_serve->get_permission_tree();
		$this->smarty->assign('permission_tree', $permission_tree);
		$this->smarty->display('permission/permission_list.htm');
	}
	
	function alloc_show()
	{
		$permission_serve = parent::get_serve();
		$permission_serve->check_permission('PERMISSION_ALLOCATION');

		$user_name = $_GET['user_name'];
		$permission_tree = $permission_serve->get_permission_tree_by_user_name($user_name);
		$this->smarty->assign('user_name', $user_name);
		$this->smarty->assign('alloc', true);
		$this->smarty->assign('permission_tree', $permission_tree);
		$this->smarty->display('permission/alloc.htm');
	}
	
	function alloc()
	{
		$permission_serve = parent::get_serve();
		$permission_serve->check_permission('PERMISSION_ALLOCATION');
		$user_name = $_REQUEST['user_name'];
		$list = array();
		foreach($_POST as $k => $v) {
			if ($v == "on")
			{
				$tmp = explode('_', $k, 2);
				if ($tmp[0] == "permission" && !empty($tmp[1])) {
					$list[] = $tmp[1];
				}
			}
		}
		$permission_serve->update_permission_list($user_name, $list);
		p('更新成功');
	}
}